package com.kayden.ioc;

import com.kayden.ioc.component.UserComponent;
import com.kayden.ioc.config.UserConfig;
import com.kayden.ioc.controller.HController;
import com.kayden.ioc.controller.HelloController;
import com.kayden.ioc.model.Student;
import com.kayden.ioc.rep.UserRepository;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
//@ComponentScan({"com.kayden.ioc.service","com.kayden.ioc.component"})
public class DempApplication {

    public static void main(String[] args) {
        //SpringApplication.run(DempApplication.class, args);
        //获取Spring上下⽂对象
        ApplicationContext context = SpringApplication.run(DempApplication.class, args);

        //从Spring上下⽂中获取对象
//        HelloController bean = context.getBean(HelloController.class);
//        bean.print();

        //HelloController bean = context.getBean(HelloController.class);
        //bean.print();

//        HelloController helloController = new HelloController();
//        helloController.print();
//
//        HelloController bean2 = (HelloController) context.getBean("helloController");
//        bean2.print();
//
//        HelloController bean3 = context.getBean("helloController",HelloController.class);
//        bean3.print();
//
// 		System.out.println(bean);
//		System.out.println(bean2);
//		System.out.println(bean3);

//        HelloController bean1 = (HelloController) context.getBean("helloController");
//        bean1.print();

//        HController bean5 = (HController) context.getBean("aaa");
//        bean5.print();
        //UserService bean = context.getBean(UserService.class);
//		bean.print();
		UserRepository bean2 = context.getBean(UserRepository.class);
		bean2.print();
//        UserComponent bean3 = context.getBean(UserComponent.class);
//        bean3.print();
//        UserConfig bean4 = context.getBean(UserConfig.class);
//        bean4.print();

        //@Bean
//        Student bean = (Student)context.getBean("s3");
//        System.out.println(bean);
//        Student bean2 = (Student) context.getBean("s2");
//        System.out.println(bean2);
    }
}
